// index.js
// 获取应用实例
const app = getApp()
import {
  getCaItemRentalPage
} from "../../../api/place.js";
import {
  getCmCommentPage,
  getCmCommentAppendPage
} from "../../../api/post.js";
Page({
  data: {
    camp:'',
option:0,
type:2,
campid:1,
  },

  onChange(e) {
    const {
      index
    } = e.detail;

    // console.log(index);
  },
  // 事件处理函数
  bindViewTap() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
    go: function () {
      let id =  this.data.camp.id
      id = JSON.stringify(id)
      let type=this.data.type;
      let campid=this.data.campid
      let data={
        id:id,
        type:type,
        campid:campid
      }
      data = JSON.stringify(data)
    wx.navigateTo({
      url: '../payment/payment?data='+data
    })
  },
  onLoad(options) {
    let data = JSON.parse(options.data);
    this.data.campid = JSON.parse(data.campid)

    this.getCaItemRentalPage(data)
    this.getCmCommentPage(data)
  },
  getCmCommentPage(id) {
    let data = {
      "pageNum": "1",
      "pageSize": "10",
      "id": null,
      "uaUserId": null,
      "commentType": 2,
      "commentTypeId": id.id,
      "commentText": null,
      "praiseNum": null,
      "followNum": null,
      "status": null,
      "delFlag": null,
      "createBy": null,
      "createTime": null,
      "updateBy": null,
      "updateTime": null,
      "remark": null
    }
    getCmCommentPage(data).then(res => {
      let datalist = res.data.data.records;
      console.log(datalist)
      this.setData({
        datalist: datalist,
        num: datalist.length,
        
      })
      datalist.forEach((item,index)=>{
        this.getCmCommentAppendPage(item.id,index)
      })
    })
    
  },
  getCmCommentAppendPage(id,index) {
    let data = {
      "pageNum": "1",
      "pageSize": "10",
      "id": null,
      "cmCommentId":id,
      "uaUserId": null,
      "commentText": null,
      "praiseNum": null,
      "status": null,
      "delFlag": null,
      "createBy": null,
      "createTime": null,
      "updateBy": null,
      "updateTime": null,
      "remark": null
    }
    getCmCommentAppendPage(data).then(res => {
      let datalist1 = res.data.data.records;
      console.log(datalist1)
      let total = res.data.data.total

      let datalist = this.data.datalist

      datalist[index].datalist1 = datalist1
      datalist[index].total = total

      this.setData({
        datalist: datalist,
      })
    })
  },
  getCaItemRentalPage(option) {
    let data ={
      "pageNum": "1",
      "pageSize": "10",
      "id": option.id,
      "caCampId": option.campid,
      "titleText": null,
      "detailText": null,
      "photoUrl": null,
      "price": null,
      "percentage": null,
      "service": null,
      "inventory": null,
      "praiseNum": null,
      "collectionNum": null,
      "status": null,
      "delFlag": null,
      "createBy": null,
      "createTime": null,
      "updateBy": null,
      "updateTime": null,
      "remark": null
    }
    getCaItemRentalPage(data).then(res => {
      let camp = res.data.data.records[0];
      // let camp = res.data.data.records[0].caCamp;

      console.log(res);
      this.setData({
        camp: camp,
      })
    })
  },


  getprice(e) {
    let index = e.currentTarget.dataset.index;
    console.log(e);
    this.setData({
      index:index,
    })
  },
})